# Python 3.8

import pandas as pd
import glob as glob

## Functions
def combine_files(prefix_string):
	file_list = glob.glob(prefix_string)
	return pd.concat([pd.read_csv(f) for f in file_list], ignore_index=True)

# def read_DataFrame_and_Add_Parameters(file_name):
# 	parameters = file_name.split("/Path/Data/OUTPUT_R_")[1].split(".csv.gz")[0].split("_")

# 	file_ = pd.read_csv(file_name)
# 	file_["Sample_Stratified"] = parameters[-5]
# 	file_["Citation_Deflated"] = parameters[-4]
# 	file_["Citation_Window"] = parameters[-3]
# 	file_["Citation_Logged"] = parameters[-2]
	
# 	file_.to_csv(file_name, ignore_index=True)

# def combine_files_and_add_parameters(prefix_string):
# 	file_list = glob.glob(prefix_string)
# 	for f in file_list:
# 		read_DataFrame_and_Add_Parameters(f)


## Disciplines
# ['Medicine','Business','Computer Science','Biology','Environmental Science','Physics','Economics','Geology','Mathematics','Psychology','Chemistry','Materials Science']:

diversity_df = combine_files('/Path/Data/OUTPUT_R_NODF_Diversity_*')
diversity_df.to_csv('/Path/Data/COMBINED_OUTPUT_R_NODF_Diversity.csv.gz',compression='gzip',index=False)

ubiquity_df = combine_files('/Path/Data/OUTPUT_R_NODF_Ubiquity_*')
ubiquity_df.to_csv('/Path/Data/COMBINED_OUTPUT_R_NODF_Ubiquity.csv.gz',compression='gzip',index=False)

citation_df = combine_files('/Path/Data/OUTPUT_R_NODF_Citations_*')
citation_df.to_csv('/Path/Data/COMBINED_OUTPUT_R_NODF_Citations.csv.gz',compression='gzip',index=False)

#combine_files_and_add_parameters('/Path/Data/OUTPUT_R_NODF_Matrix_Citations_*')
matrix_citation_df = combine_files('/Path/Data/OUTPUT_R_NODF_Matrix_Citations_*')
matrix_citation_df.to_csv('/Path/Data/COMBINED_OUTPUT_R_NODF_Matrix_Citations.csv.gz',compression='gzip',index=False)

#combine_files_and_add_parameters('/Path/Data/OUTPUT_R_Ideal_NODF_Matrix_Citations_*')
ideal_nodf_df = combine_files('/Path/Data/OUTPUT_R_Ideal_NODF_Matrix_Citations_*')
ideal_nodf_df.to_csv('/Path/Data/COMBINED_OUTPUT_R_Ideal_NODF_Matrix_Citations.csv.gz',compression='gzip',index=False)

#combine_files_and_add_parameters('/Path/Data/OUTPUT_R_Predicted_Values_*')
predicted_df = combine_files('/Path/Data/OUTPUT_R_Predicted_Values_*')
predicted_df.to_csv('/Path/Data/COMBINED_OUTPUT_R_Predicted_Values.csv.gz',compression='gzip',index=False)

